package math;


public class Variable implements ArithmeticExpression {

  private String name;

  public Variable(String name) {
    this.name = name;
  }

  public String getName() {
    return name;
  }

  @Override
  public boolean isOne() {
    return false;
  }

  @Override
  public boolean isZero() {
    return false;
  }

  @Override
  public ArithmeticExpression derivate(Variable var) {
    return var.equals(this) ? IntegerConstant.ONE : IntegerConstant.ZERO;
  }

  @Override
  public boolean equals(Object obj) {
    if (obj instanceof Variable) {
      Variable var2 = (Variable) obj;
      return var2.name.equals(name);
    } else
      return false;
  }
  
  @Override
  public int hashCode() {
    return name.hashCode();
  }

  @Override
  public int getPriority() {
    return 1;
  }
  
  @Override
  public String toString() {
    return name;
  }

  @Override
  public ArithmeticExpression simplify() {
    return this;
  }

  @Override
  public boolean matches(Expression expr) {
    if (expr instanceof Variable) {
      Variable eVar = (Variable) expr;
      return name.equals(eVar.getName());
    } else
      return false;
  }

  @Override
  public int countMembers() {
    return 1;
  }

  @Override
  public <R> R accept(ExpressionVisitor<R> visitor) {
    return visitor.visitVariable(this);
  }
}